package com.example.ntpsynchronoustime.utils;

/**
 * 单例模板类
 * @param <T> 单例的实例
 */
public abstract class Singleton<T> {

    private volatile T mInstance;

    protected abstract T create();

    public final T get() {
        if (mInstance == null) {
            synchronized (this) {
                if (mInstance == null) {
                    mInstance = create();
                }
                return mInstance;
            }
        }
        return mInstance;
    }

}
